package com.ruoyi.apiserver.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.PageInfo;
import com.ruoyi.apiserver.base.MhBaseController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.mhorders.domain.MhOrder;
import com.ruoyi.mhorders.service.IMhOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.apiserver.utils.JwtUtils;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 订单接口
 *
 * @author ruoyi
 */
@Api(tags = "订单接口")
@RestController
@RequestMapping("/api/order")
public class OrderController extends MhBaseController {

    @Autowired
    private IMhOrderService orderService;


    /**
     * 查询订单列表
     */
    @ApiOperation("查询订单列表")
    @GetMapping("/list")
    public TableDataInfo list(MhOrder mhOrder) {
        // 从token中获取用户ID
        // 这里简化处理，实际项目中需要通过手机号查询用户ID
        mhOrder.setUserId(getUserId());
        PageUtils.startPage();
        List<MhOrder> list = orderService.selectMhOrderList(mhOrder);

        TableDataInfo rspData = new TableDataInfo();

        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }

    /**
     * 获取订单详细信息
     */
    @ApiOperation("获取订单详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(orderService.selectMhOrderById(id));
    }
    /**
     * 删除订单
     */
    @ApiOperation("删除订单")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success("操作成功", orderService.deleteMhOrderByIds(ids));
    }
}